package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.DeviceOnlineOfflineRecordService;
import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.dto.DeviceDto;
import com.huilian.iotbox.data.dto.DeviceOnlineOfflineRecordDto;
import com.huilian.iotbox.data.enums.RoleEnum;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author LinYinDong
 * @date 2024/2/27 14:46
 */
@RestController
@RequestMapping("/api/deviceOnlineOfflineRecord")
public class DeviceOnlineOfflineRecordController extends BaseController {
    @Autowired
    private UserService userService;
    @Resource
    private DeviceOnlineOfflineRecordService deviceOnlineOfflineRecordService;
    @PostMapping("/deviceOnlineOfflineList")
    public ServerResponse deviceOnlineOfflineList(@RequestBody DeviceOnlineOfflineRecordDto deviceOnlineOfflineRecordDto, HttpServletRequest request) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
//        if (!RoleEnum.SUPER_ADMINISTRATOR.getRoleId().equals(userInfo.getRoleId())) {
//            return ServerResponse.createByErrorMessage("你没有权限查看设备上线离线时间点");
//        }
        if(StringUtils.isEmpty(deviceOnlineOfflineRecordDto.getDeviceNo())){
            return ServerResponse.createByErrorMessage("设备号不能为空");
        }
        deviceOnlineOfflineRecordDto.setUserInfo(userInfo);
        deviceOnlineOfflineRecordDto.setPageNum(Integer.parseInt(request.getParameter("pageNum")));
        deviceOnlineOfflineRecordDto.setPageSize(Integer.parseInt(request.getParameter("pageSize")));
        return ServerResponse.createBySuccess(deviceOnlineOfflineRecordService.deviceOnlineOfflineByDeviceNoList(deviceOnlineOfflineRecordDto));
    }
}
